package com.xiaoshuidi.cloud.module.member.enums;

import cn.hutool.core.lang.Assert;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum SexEnum {
    MALE(1, "男"),
    FEMALE(2, "女");
    private Integer code;
    private String name;

    public static String getNameByCode(Integer code) {
        SexEnum sexEnum = Arrays.stream(SexEnum.values()).filter(p -> p.code.intValue() == code.intValue()).findFirst().orElse(null);
        Assert.isTrue(sexEnum != null, "SexEnum:{}不存在", code);
        return sexEnum.getName();
    }
}
